1. Field of the Invention
The present invention relates to an image processing apparatus, a focus adjusting method, and a computer program, which are capable of extracting a plurality of candidate focus positions and selecting an optimum focus position among the plurality of extracted candidate focus positions while viewing those positions.
2. Description of Related Art
In the case of inspecting whether or not a defect is present in an inspection object, an appearance of the inspection object is imaged by an imaging device to determine whether or not the defect is present based on the imaged image. Proper determination of the presence of the defect requires the imaged image to be clear, and normally, the inspection object is imaged after focus adjustment is performed. Manual adjustment or automatic adjustment is performed as the focus adjustment, where the automatic adjustment is easier to use for the user.
In the case of automatically performing the focus adjustment, an adjustment region such as a rectangular region or a circular region for adjusting a focus is set, and the focus degree of each of imaged images with regard to an inspection object imaged within the set adjustment region is evaluated, to extract a position with the highest focus degree as a focus position. For example, Japanese Unexamined Patent Publication No. 2007-316432 discloses an enlarging observation device for calculating focus values each indicating the degree of focus by an imaging unit to extract a maximum focus value which is a focus value being maximal, and moving the imaging unit to a maximum focus position corresponding to the maximum focus value, to thereby adjust a subject distance from the imaging unit to the inspection object.
The focus degree has hitherto been evaluated based on a quantity of high-frequency components of image data. That is, it has been evaluated that a position with a larger quantity of high-frequency components being within the set adjustment region is more focused, and a position with a smaller quantity of higher-frequency component is less focused.
However, in the case of extracting the high-frequency component only within the set adjustment region, there may occur a case where an unintended evaluation is made due to an influence of a size of the adjustment region or an influence of blurring on the periphery of the adjustment region. FIGS. 1A and 1B are schematic views for describing a problem of the conventional evaluation of the focus degree.
As shown in FIG. 1A, in a so-called non-focused state in which the image is not focused, a blurred portion 501 is present on the periphery of a characteristic portion 500 of the inspection object, as compared with a so-called focused state in which the image is focused, shown in FIG. 1B. When an adjustment region 502 is set in this state, the background color is one in the focused state of FIG. 1B, whereas a color different from the background color is mixed due to the presence of the blurred portion 501 in the non-focused state of FIG. 1A. As a result, the quantity of high-frequency components is likely to be determined to be larger than that in FIG. 1B, and hence the focus degree might be wrongly recognized as higher in the non-focused state shown in FIG. 1A.
Further, in the non-focused state shown in FIG. 1A, since the image becomes an image including the blurred portion 501 being present at the periphery of the characteristic portion 500 of the inspection object, setting of an appropriate adjustment region 502 itself is difficult. That is, in the case of the blurred portion 501 being present, it may not be possible to properly perform the focus adjustment depending on setting of the window (adjustment region). Moreover, “requiring the focus adjustment” means the image is not focused, and since the user is made to perform an operation for setting the window (adjustment region) on the non-focused image, setting of the window (adjustment region) has become more difficult.